import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)


const routes = [
  {
    path: "/",
    name: '首页',
    component: () => import('../views/Layout/Layout.vue'),
    redirect: '/home',
    children: [
      {
        path: "/home",
        name: '首页',
        component: () => import('../views/Home/Home.vue'),
      },
      // 商品路由页
      {
        path: '/pms',
        name: '商品',
        component: () => import('../views/Goods/pms.vue'),
        redirect: '/pms/product',
        children: [
          {
            path: '/pms/product',
            name: '商品列表',
            component: () => import('../views/Goods/product.vue'),
          },
          {
            path: "/pms/addProduct",
            name: '添加商品',
            component: () => import('../views/Goods/addProduct.vue'),
          },
        ]
      },
      {
        path: '/oms',
        name: '订单',
        component: () => import('../views/Order/oms.vue'),
        redirect: '/oms/order',
        children: [
          {
            path: '/oms/order',
            name: '订单列表',
            component: () => import('../views/Order/order.vue')
          }
        ]
      },
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/Login/Login.vue'),
  },


]

const router = new VueRouter({
  routes
})
// console.log(routes)
// router.beforeEach((to, from, next) => {
//   // console.log(to)
//   let paths = to.path
//   let names = to.path.slice(1)
//   let ro = {
//     path: paths,
//     name: names,
//     component: () => import('../views/' + names.charAt(0).toUpperCase() + names.slice(1) + '/' + names.charAt(0).toUpperCase() + names.slice(1))
//   }
//   let flag = router.getRoutes().some((item) => item.name === names)
//   if (flag) {
//     next()
//   } else {
//     router.addRoute(ro)
//     next({ ...to })
//   }
//   // routes.push(ro)
// })

export default router
